import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:logger/logger.dart';

class ImageUtils {

  static final ImagePicker _picker = ImagePicker();
  static final Logger _logger = Logger();

  static Future<File?> pickImageFromGallery() async {
    try {
      final XFile? imageFile = await _picker.pickImage(source: ImageSource.gallery);

      if (imageFile == null) {
        _logger.i("取消选择图片");
        return null;
      }

      return File(imageFile.path);
    } catch (e) {
      _logger.e("选择图片失败: $e");
      return null;
    }
  }

   static Future<File?> pickImageFromCamera() async {
    try {
      final XFile? imageFile = await _picker.pickImage(source: ImageSource.camera);

      if (imageFile == null) {
        _logger.i("取消拍照");
        return null;
      }

      return File(imageFile.path);
    } catch (e) {
      _logger.e("拍照失败: $e");
      return null;
    }
  }
}
